package com.umeng.analytics.pro;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public class cj {
    private final df a;
    private final ds b;

    public cj() {
        this(new cz.a());
    }

    public cj(dh arg2) {

        this.b = new ds();
        this.a = arg2.a(this.b);
    }

    public void a(cg arg3, byte[] arg4) throws cm {
        try {
            this.b.a(arg4);
            arg3.a(this.a);
        } catch (Throwable v0) {
            this.b.e();
            this.a.B();
            throw v0;
        }

        this.b.e();
        this.a.B();
    }

    private Object a(byte arg3, byte[] arg4, cn arg5, cn[] arg6) throws cm {
        int v1 = 11;
        try {
            da v0_2 = this.j(arg4, arg5, arg6);
            if (v0_2 != null) {
//                return v0_2;
            } else {
                return null;
            }

            switch (arg3) {
                case 2: {
                    if (v0_2.b == 2) {
                        return Boolean.valueOf(this.a.t());
                    } else {
                        return null;
                    }
                }
                case 3: {
                    if (v0_2.b == 3) {
                        return Byte.valueOf(this.a.u());
                    } else {
                        return null;
                    }
                }
                case 4: {
                    if (v0_2.b == 4) {
                        return Double.valueOf(this.a.y());
                    } else {
                        return null;
                    }
                }
                case 6: {
                    if (v0_2.b == 6) {
                        return Short.valueOf(this.a.v());
                    } else {
                        return null;
                    }
                }
                case 8: {
                    if (v0_2.b == 8) {
                        return Integer.valueOf(this.a.w());
                    } else {
                        return null;
                    }
                }
                case 10: {
                    if (v0_2.b == 10) {
                        return Long.valueOf(this.a.x());
                    } else {
                        return null;
                    }
                }
                case 11: {
                    if (v0_2.b == v1) {
                        return this.a.z();
                    } else {
                        return null;
                    }
                }
                case 100: {
                    if (v0_2.b == v1) {
                        return this.a.A();
                    } else {
                        return null;
                    }
                }
            }
        } catch (Exception e) {
            return null;
        } finally {
            this.b.e();
            this.a.B();
        }
        return null;
    }

    public Boolean a(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (Boolean) this.a((byte) 2, arg2, arg3, arg4);
    }

    public void a(cg arg2, String arg3) throws cm {
        this.a(arg2, arg3.getBytes());
    }

    public void a(cg arg4, String arg5, String arg6) throws cm {
        try {
            this.a(arg4, arg5.getBytes(arg6));
        } catch (UnsupportedEncodingException v0_1) {
            try {
                throw new cm("JVM DOES NOT SUPPORT ENCODING: " + arg6);
            } catch (Throwable v0) {
                this.a.B();
                throw v0;
            }
        }

        this.a.B();
    }

    public void a(cg arg3, byte[] arg4, cn arg5, cn[] arg6) throws cm {
        try {
            if (this.j(arg4, arg5, arg6) != null) {
                arg3.a(this.a);
            }
        } catch (Exception v0_1) {
            try {
                throw new cm(((Throwable) v0_1));
            } catch (Throwable v0) {
                this.b.e();
                this.a.B();
                throw v0;
            }
        }

        this.b.e();
        this.a.B();
    }

    public Byte b(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (Byte) this.a((byte) 3, arg2, arg3, arg4);
    }

    public Double c(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (Double) this.a((byte) 4, arg2, arg3, arg4);
    }

    public Short d(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (Short) this.a((byte) 6, arg2, arg3, arg4);
    }

    public Integer e(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (Integer) this.a((byte) 8, arg2, arg3, arg4);
    }

    public Long f(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (Long) this.a((byte) 10, arg2, arg3, arg4);
    }

    public String g(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (String) this.a((byte) 11, arg2, arg3, arg4);
    }

    public ByteBuffer h(byte[] arg2, cn arg3, cn[] arg4) throws cm {
        return (ByteBuffer) this.a((byte) 100, arg2, arg3, arg4);
    }

    public Short i(byte[] arg3, cn arg4, cn[] arg5) throws cm {
        Short v0_2;
        try {
            if (this.j(arg3, arg4, arg5) != null) {
                this.a.j();
                v0_2 = Short.valueOf(this.a.l().c);
            } else {
                this.b.e();
                this.a.B();
                return null;
            }
        } catch (Exception v0_1) {
            try {
                throw new cm(((Throwable) v0_1));
            } catch (Throwable v0) {
                this.b.e();
                this.a.B();
                throw v0;
            }
        }

        this.b.e();
        this.a.B();
        return v0_2;

    }

    private da j(byte[] arg7, cn arg8, cn[] arg9) throws cm {
        da v2 = null;
        int v1 = 0;
        this.b.a(arg7);
        cn[] v3 = new cn[arg9.length + 1];
        v3[0] = arg8;
        int v0;
        for (v0 = 0; v0 < arg9.length; ++v0) {
            v3[v0 + 1] = arg9[v0];
        }

        this.a.j();
        da v0_1 = v2;
        while (true) {
            if (v1 < v3.length) {
                v0_1 = this.a.l();
                if (v0_1.b != 0 && v0_1.c <= v3[v1].a()) {
                    if (v0_1.c != v3[v1].a()) {
                        di.a(this.a, v0_1.b);
                        this.a.m();
                    } else {
                        ++v1;
                        if (v1 >= v3.length) {
                            continue;
                        }

                        this.a.j();
                    }

                    continue;
                }
            } else {
                return v0_1;
            }

            return v2;
        }
    }
}

